package jface.util;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class MyWizardPageB extends WizardPage{
	
	private Text firstName;
	private Text lastName;

	protected MyWizardPageB() {
		super("My Second Page");
	}

	public void createControl(Composite parent) {
		setTitle("Enter your Partners Details");
		setMessage("Your Partner identification is required");
		Composite composite = new Composite(parent, SWT.NONE);
		composite.setLayout(new GridLayout(1, true));

		new Label(composite, SWT.NONE).setText("First Name:");
		firstName = new Text(composite, SWT.BORDER);
		firstName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		firstName.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				setPageComplete(isPageComplete());
			}
		});

		new Label(composite, SWT.NONE).setText("Last Name:");
		lastName = new Text(composite, SWT.BORDER);
		lastName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		lastName.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				setPageComplete(isPageComplete());
			}
		});

		setControl(composite);
	}
	
	public boolean isPageComplete() {
		if(firstName.getText().isEmpty()){
			setErrorMessage("First Name missing");
			return false;
		}
		if(lastName.getText().isEmpty()){
			setErrorMessage("Last Name missing");
			return false;
		}
		setErrorMessage(null);
		return true;
	}

}
